package com.medaxis.hpams.sso.controller;

import com.medaxis.hpams.dto.global.BaseResponse;
import com.medaxis.hpams.dto.global.SuccessResponse;
import com.medaxis.hpams.sso.constant.Constants;
import com.medaxis.hpams.sso.domain.dto.DictDataDto;
import com.medaxis.hpams.sso.service.DictDataService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping(Constants.VERSION_NUMBER+"/sso/dict/data")
@Api(tags = Constants.VERSION_NUMBER+"字典数据管理")
public class DictDataController extends BaseController {

    @Autowired
    private DictDataService dictDataService;
    
//    @GetMapping("/list")
//    @ApiOperation(value = "根据字典类型查询数据列表", httpMethod = "GET")
//    @ApiImplicitParam(name = "dictType", value = "字典类型", dataType = "String", required = true)
//    public BaseResponse list(DictDataDto dictDataDto) {
//        startPage();
//        List<DictDataDto> list = dictDataService.selectDictDataList(dictDataDto);
//        return SuccessResponse.success(list);
//    }


    /**
     * 查询字典数据详细
     */
    @ApiOperation(value = "根据字典数据详情信息", httpMethod = "GET")
    @GetMapping(value = "/{id}")
    public BaseResponse getInfo(@PathVariable Long id) {
        return SuccessResponse.success(dictDataService.selectDictDataById(id));
    }

    /**
     * 根据字典类型查询字典数据信息
     */
    @ApiOperation(value = "根据字典类型查询字典数据信息", httpMethod = "GET")
    @ApiImplicitParam(name = "dictType", value = "字典类型（标识字段）", dataType = "String", required = true)
    @GetMapping(value = "/type/{dictType}")
    public BaseResponse getDataByDictType(@PathVariable String dictType) {
        startPage();
        return SuccessResponse.success(dictDataService.selectDictDataByType(dictType));
    }

    /**
     * 新增字典数据
     */

    @ApiOperation(value = "新增字典数据信息", httpMethod = "POST")
    @PostMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "字典数据状态", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "dictType", value = "字典类型", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "字典数据名称", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "value", value = "字典数据值", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "字典数据id", required = true, dataType = "String", paramType = "query"),
    })
    public BaseResponse add(@Validated DictDataDto dictDataDto) {
        // todo 添加创建人
        dictDataDto.setCreateBy("admin");
        return new SuccessResponse(dictDataService.insertDictData(dictDataDto));
    }

    /**
     * 修改字典数据
     */
    @PutMapping("/edit")
    @ApiOperation(value = "修改字典数据", httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "字典数据状态", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "dictType", value = "字典类型", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "字典数据名称", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "value", value = "字典数据值", required = true, dataType = "String", paramType = "query"),
    })
    public BaseResponse edit(@Validated DictDataDto dictDataDto) {
        //todo 添加更新人
        dictDataDto.setCreateBy("admin");
        return toBaseResponse(dictDataService.updateDictData(dictDataDto));
    }

    /**
     * 删除字典数据
     */
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除字典数据", httpMethod = "DELETE")
    public BaseResponse remove(@PathVariable Long[] ids) {
        return toBaseResponse(dictDataService.deleteDictDataByIds(ids));
    }

}
